// import { array2Obj } from '@/utils/bizUtils';
const onlineTipContent = '价格来源类型为线上网站时此字段必填'
const offlineTipContent = '价格来源类型为线下生产商时此字段必填'
// 状态列表
const STATE_OPTIONS = [
  {
    label: '待更新',
    value: '1'
  },
  {
    label: '已更新',
    value: '2'
  }
]
// 浮动预警值类型
const FLOAT_WARNING_VALUES = [
  { label: '比例', value: 1 },
  { label: '金额', value: 2 }
]
// 价格来源类型
const PRICE_SOURCE_TYPE = [
  { label: '线上网站', value: 1 },
  { label: '线下生产商', value: 2 }
]
export const FORM_ITEMS = [
  {
    prop: 'name',
    label: '原材料名称',
    type: 'input'
  },
  {
    prop: 'state',
    label: '更新状态',
    type: 'select',
    options: STATE_OPTIONS
  },
  {
    prop: 'updatedDate',
    label: '更新日期',
    type: 'datePicker',
    datePickerType: 'daterange',
    valueFormat: 'yyyy-MM-dd'
  }
]
// 列表表头
export const TABLE_COLUMNS = [
  {
    title: '原材料编码',
    key: 'id',
    sortable: true,
    width: 110
  },
  {
    title: '原材料名称',
    key: 'name',
    width: 100
  },
  {
    title: '规格',
    key: 'spec'
  },
  {
    title: '计量单位',
    key: 'unitName'
  },
  {
    title: '原材料生产商',
    key: 'producer'
  },
  {
    title: '当前价格',
    key: 'price'
  },
  {
    title: '更新日期',
    key: 'updatedDate',
    width: 100,
    sortable: true
  },
  // 1待更新/2已更新
  {
    title: '更新状态',
    key: 'stateStr'
  },
  {
    title: '操作人',
    key: 'operName'
  },
  {
    title: '创建日期',
    key: 'createdDate'
  },
  {
    title: '创建人',
    key: 'createOper'
  },
  // 1比例/2金额
  {
    title: '浮动预警值类型',
    key: 'warningTypeStr',
    width: 120
  },
  {
    title: '浮动预警值',
    key: 'warningValueStr',
    width: 110
  },
  {
    title: '浮动预警值说明',
    key: 'warningDesc',
    width: 110
  },
  {
    title: '预警起始价格',
    key: 'warningPrice',
    width: 110
  },
  {
    title: '预警价格起始日期',
    key: 'warningPriceStartDate',
    width: 120
  },
  {
    title: '价格来源类型',
    key: 'priceSourceTypeStr',
    width: 110
  },
  {
    title: '价格来源',
    key: 'priceSource'
  },
  {
    title: '网址',
    key: 'website'
  },
  {
    title: '公司名称',
    key: 'companyName'
  },
  {
    title: '联系电话',
    key: 'telephone'
  },
]
// 原材料新增
export const getAddTableColumns = (parent) => {
  return [
    {
      title: '原材料名称',
      key: 'name',
      type: 'inputNoLimit',
      maxlength: 100,
      showLimit: true,
      required: true,
      width: 150
    },
    {
      title: '规格',
      key: 'spec',
      type: 'inputNoLimit',
      maxlength: 100,
      showLimit: true,
      width: 150
    },
    {
      title: '计量单位',
      key: 'unitUuid',
      required: true,
      width: 180,
      render: (h, { row, index }) => {
        const RemoteSelect = parent.RemoteSelect;
        return <RemoteSelect
          placeholder="请选择"
          optionKeys={['unitName', 'unitUuid']}
          echoValue={row.unitUuid}
          echoOptions={[row.unitName, row.unitUuid]}
          remoteSelectOptions={parent.remoteOptionsByUnit}
          handleClickButton={() => parent.handleChooseMainUnit(row)}
          onGetSelect={(data) => { parent.getUnitByRemote(data, row) }}
        />
      }
    },
    {
      title: '原材料生产商',
      key: 'producer',
      type: 'inputNoLimit',
      maxlength: 100,
      showLimit: true,
      width: 150,
      placeholder: '如天钢联合'
    },
    {
      title: '当前价格(元)',
      key: 'price',
      type: 'inputNumSpecial',
      precision: 3,
      width: 160,
      required: true,
    },
    {
      title: '浮动预警值类型',
      key: 'warningType',
      width: 160,
      type: 'select',
      options: FLOAT_WARNING_VALUES,
      required: true,
    },
    {
      title: '浮动预警值',
      key: 'warningValue',
      type: 'inputNumSpecial',
      minVal: 1,
      precision: 0,
      width: 160,
      required: true,
    },
    {
      title: '浮动预警值说明',
      key: 'warningDesc',
      type: 'inputNoLimit',
      maxlength: 200,
      showLimit: true,
      width: 150,
    },
    {
      title: '价格来源类型',
      key: 'priceSourceType',
      width: 160,
      type: 'select',
      options: PRICE_SOURCE_TYPE,
      required: true,
    },
    {
      title: '价格来源',
      key: 'priceSource',
      type: 'inputNoLimit',
      maxlength: 100,
      showLimit: true,
      width: 150,
      headTip: onlineTipContent
    },
    {
      title: '网址',
      key: 'website',
      type: 'inputNoLimit',
      maxlength: 100,
      showLimit: true,
      width: 150,
      headTip: onlineTipContent
    },
    {
      title: '公司名称',
      key: 'companyName',
      type: 'inputNoLimit',
      maxlength: 100,
      showLimit: true,
      width: 150,
      headTip: offlineTipContent
    },
    {
      title: '联系电话',
      key: 'telephone',
      type: 'inputNoLimit',
      maxlength: 100,
      showLimit: true,
      width: 150,
      headTip: offlineTipContent
    },
  ]
}
// 编辑原材料表头
export const EIDT_TABLE_COLUMNS = [
  {
    title: '原材料名称',
    key: 'name',
    type: 'inputNoLimit',
    maxlength: 100,
    showLimit: true,
    required: true,
    width: 150
  },
  {
    title: '原材料编码',
    key: 'id',
    width: 100
  },
  {
    title: '规格',
    key: 'spec',
    type: 'inputNoLimit',
    maxlength: 100,
    showLimit: true,
    width: 150
  },
  {
    title: '计量单位',
    key: 'unitName',
  },
  {
    title: '原材料生产商',
    key: 'producer',
    type: 'inputNoLimit',
    maxlength: 100,
    showLimit: true,
    width: 150,
  },
  {
    title: '当前价格(元)',
    key: 'price',
    type: 'inputNumSpecial',
    precision: 3,
    width: 160,
    required: true,
  },
  {
    title: '浮动预警值类型',
    key: 'warningTypeStr',
    width: 110,
  },
  {
    title: '浮动预警值',
    key: 'warningValue',
    type: 'inputNumSpecial',
    minVal: 1,
    precision: 0,
    width: 160,
    required: true,
  },
  {
    title: '预警起始价格',
    key: 'warningPrice',
  },
  {
    title: '浮动预警值说明',
    key: 'warningDesc',
    type: 'inputNoLimit',
    maxlength: 200,
    showLimit: true,
    width: 150,
  },
  {
    title: '价格来源类型',
    key: 'priceSourceType',
    width: 160,
    type: 'select',
    options: PRICE_SOURCE_TYPE,
    required: true,
  },
  {
    title: '价格来源',
    key: 'priceSource',
    type: 'inputNoLimit',
    maxlength: 100,
    showLimit: true,
    width: 150,
    headTip: onlineTipContent
  },
  {
    title: '网址',
    key: 'website',
    type: 'inputNoLimit',
    maxlength: 100,
    showLimit: true,
    width: 150,
    headTip: onlineTipContent
  },
  {
    title: '公司名称',
    key: 'companyName',
    type: 'inputNoLimit',
    maxlength: 100,
    showLimit: true,
    width: 150,
    headTip: offlineTipContent
  },
  {
    title: '联系电话',
    key: 'telephone',
    type: 'inputNoLimit',
    maxlength: 100,
    showLimit: true,
    width: 150,
    headTip: offlineTipContent
  },
  {
    title: '预警价格起始日期',
    key: 'warningPriceStartDate',
    width: 140,
  },
]
// 原材料价格走势详情表头
export const PRICE_MOVEMENTS_COLUMNS = [
  {
    title: '原材料名称',
    key: 'rawMaterialName',
  },
  {
    title: '规格名称',
    key: 'rawMaterialSpec',
  },
  {
    title: '计量单位',
    key: 'rawMaterialUnitName',
    width: 80
  },
  {
    title: '原材料生产商',
    key: 'rawMaterialProducer',
  },
  {
    title: '当前价格（元）',
    key: 'rawMaterialPrice',
  },
  {
    title: '更新日期',
    key: 'createdTimeStr',
  },
  {
    title: '操作人',
    key: 'operName',
  },
  {
    title: '浮动预警值',
    key: 'rawMaterialWarningValueStr',
  },
  {
    title: '预警起始价格(元)',
    key: 'rawMaterialWarningPrice',
  },
  {
    title: '预警价格起始日期',
    key: 'rawMaterialWarningPriceStartTimeStr',
  },
]
